<template>
  <div class="cart-container">
    <div class="goods-list">
      <!-- 商品列表 -->
      <div class="mui-card" v-for="(item, index) in $store.state.cart" :key="index">
        <div class="mui-card-content">
          <div class="mui-card-content-inner">
            <mt-switch v-model="item.selected" @change="selectedChanged(item.id, item.selected)"></mt-switch>
            <img :src="item.thumbnail" alt="">
            <div class="info">
              <h1>{{ item.title }}</h1>
              <p>
                <span class="price">￥{{ item.price }}</span>
                <numbox :id="item.id" :count="item.count"></numbox>
                <a href="#" @click.prevent="removeGoods(item.id)">删除</a>
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 结算 -->
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner calc">
          <div class="left">
            <p>总计（不含运费）</p>
            <p>已勾选
              <span class="red">{{ $store.getters.getCartSelectedGoodsInfo.count }}</span> 件，总价
              <span class="red">￥{{ $store.getters.getCartSelectedGoodsInfo.amount }}</span>
            </p>
          </div>
          <mt-button type="danger">结算</mt-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import numbox from "../common/CartNumbox.vue";
export default {
  methods: {
    removeGoods(goodsId) {
      this.$store.commit("removeGoods", goodsId);
    },
    selectedChanged(goodsId, selected) {
      this.$store.commit("modifyGoods", { goodsId, selected });
    }
  },
  
  components: {
    numbox
  }
};
</script>

<style lang="scss" scoped>
.cart-container {
  background-color: #ddd;
  overflow: hidden;
  .goods-list {
    .mui-card-content-inner {
      display: flex;
      align-items: center;
    }
    img {
      height: 60px;
    }
    h1 {
      font-size: 13px;
    }
    .info {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .price {
        color: red;
        font-weight: bold;
      }
    }
  }
  .calc {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .left {
      .red {
        color: red;
        font-weight: bold;
        font-size: 14px;
      }
    }
  }
}
</style>
